package cn.geminis.workflow.service.service.approve;

import cn.geminis.workflow.service.entity.ApproveResult;
import cn.geminis.workflow.service.service.model.ApproveResultService;
import lombok.RequiredArgsConstructor;
import org.flowable.engine.ProcessEngine;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author puddi
 */
@Service("disagree")
@RequiredArgsConstructor
public class DisagreeImpl implements ApproveService {

    private final ProcessEngine engine;
    private final ApproveResultService approveResultService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void handle(ApproveResult approveResult) {
        approveResultService.saveApprove(approveResult);
        engine.getRuntimeService().deleteProcessInstance(approveResult.getProcessInstanceId(), approveResult.getComment());
    }

}
